package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.qingcheng.util.SmsUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

/**
 * @ProjectName: qingcheng_parent
 * @ClassName: SmsMessageConsumer
 * @Time: 2019/7/14
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
public class SmsMessageConsumer implements MessageListener {
    @Autowired
    private SmsUtil smsUtil;

    /**
     * 短信模板编号
     * 短信参数
     */
    @Value("${smsCode}")
    private String smsCode;
    @Value("${param}")
    private String param;

    @Override
    public void onMessage(Message message) {
        String jsonString = new String(message.getBody());
        Map<String,String> map = JSON.parseObject(jsonString, Map.class);
        String phone = map.get("phone");
        String code=map.get("code");
        System.out.println("手机号："+phone+"验证码："+code);

        //发送短信
//        param = param.replace("", code);
//        try {
//            smsUtil.sendSms(phone, smsCode, param);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

    }
}
